<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">callbacks.fireWith()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/callbacks-object/">回调对象</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/callbacks.fireWith/" target="_blank">callbacks.fireWith()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<article class="entry method" id="callbacks-fireWith1"><h2 class="section-title">
<span class="name">callbacks.fireWith(  [context ] [, args ] )</span><span class="returns">返回: <a href="/Types/#Callbacks">Callbacks</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>访问给定的上下文和参数列表中的所有回调。</p>
<ul class="signatures"><li class="signature" id="callbacks-fireWith-context-args">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.7/">1.7</a></span>callbacks.fireWith(  [context ] [, args ] )</h4>
<ul>
<li>
<div><strong>context</strong></div>
<div>Type: </div>
<div>该列表中的回调被触发的上下文引用</div>
</li>
<li>
<div><strong>args</strong></div>
<div>Type: </div>
<div>一个参数或参数列表传回给回调列表。</div>
</li>
</ul>
</li></ul>
<div class="longdesc" id="entry-longdesc">
<p>此方法返回绑定它的那个回调对象(<code>this</code>).</p>
<h2 id="example-1">Example</h2>
<p>使用 <code>callbacks.fireWith()</code> 访问给定的上下文和参数列表中的所有回调:</p>
<div class="syntaxhighlighter javascript nogutter">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
<div class="line n12">12</div>
<div class="line n13">13</div>
<div class="line n14">14</div>
<div class="line n15">15</div>
<div class="line n16">16</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="comment">// a sample logging function to be added to a callbacks list</span></code></div></div><div class="container"><div class="line"><code><span class="keyword">var</span> log = <span class="keyword">function</span>( value1, value2 ) {</code></div></div><div class="container"><div class="line"><code>  console.log( <span class="string">"Received: "</span> + value1 + <span class="string">","</span> + value2 );</code></div></div><div class="container"><div class="line"><code>};</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="keyword">var</span> callbacks = $.Callbacks();</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">// add the log method to the callbacks list</span></code></div></div><div class="container"><div class="line"><code>callbacks.add( log );</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">// fire the callbacks on the list using the context "window"</span></code></div></div><div class="container"><div class="line"><code><span class="comment">// and an arguments array</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code>callbacks.fireWith( window, [<span class="string">"foo"</span>,<span class="string">"bar"</span>]);</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">// outputs: "Received: foo, bar"</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div></article> </div>
</article>